<template>
	<view :style="theme" class="content">
		<radio-group v-if="items.length != 0">
			<label class="box" v-for="(item, index) in items" :key="index" @click="radioChange(item)">
				<view class="box_left">
					<text>{{ item.couponsType == 0 ? '折扣券' : '代金券'}}</text>
					<text>{{ item.discountNum }}<text>{{ item.couponsType == 0 ? '折' : '元'}}</text></text>
					<view class="y_t"></view>
					<view class="y_b"></view>
				</view>
				<view class="box_right">
					<view class="box_right_wz">
						<view>{{ item.couponsName }}</view>
						<view v-if="item.couponsType == 0" class="js limit-2-line">订单满{{item.miniNum}}享{{item.discountNum}}折</view>
						<view v-else class="js limit-2-line">订单满{{item.miniNum}}减{{item.discountNum}}元</view>
						<view v-if="item.validityEndTime">有效期至：{{ item.validityEndTime }}</view>
					</view>
					<radio class="box_right_radio" :value="item.id" :checked="item.checked" />
				</view>
			</label>
		</radio-group>

		<view v-if="items.length === 0" class="no-order">
			<image :src="imgHost+'/default_nodata.png'"></image>
			<view>暂无优惠券～</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id: '',
				zfType: '',
				yhqId: '',
				items: []
			}
		},
		onLoad(ops) {
			this.id = ops.id
			this.zfType = ops.zfType
			this.yhqId = ops.yhqId
			this.getList()
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			radioChange(e) {
				let yhqId = e.id
				let yhqName = ''
				if (this.yhqId == e.id) {
					yhqId = ''
				} else {
					yhqName = e.couponsName
				}
				// var pages = getCurrentPages();
				// var prevPage = pages[pages.length - 2];
				// // #ifdef H5
				// prevPage.$vm.yhqId = yhqId;
				// prevPage.$vm.yhqName = yhqName;
				// // #endif
				// // #ifdef MP
				// prevPage.setData({
				// 	yhqId,
				// 	yhqName
				// });
				// // #endif
				uni.$emit('yhq', {
					yhqId,
					yhqName
				})
				uni.navigateBack()
			},
			getList() {
				this.$app.ajax({
					api: this.$api.availableCoupons(),
					data: {
						param: {
							memberId: this.userInfo.id,
							orderId: this.id,
							isMult: '1',
							payMethod: this.zfType,
							stadiumId: this.venueId
						}
					}
				}).then((res) => {
					if (res.errorCode === '000000') {
						let arr = res.recordList || []
						arr.forEach((e) => {
							if (e.id == this.yhqId) {
								e.checked = true
							} else {
								e.checked = false
							}
						})
						this.items = arr
					}
				}).catch(() => {})
			},
		}

	}
</script>
<style scoped lang="scss">
	radio .wx-radio-input {
		border-radius: 50%;
		width: 24px;
		height: 24px;
	}

	radio .wx-radio-input {
		background: #ffffff;
	}

	.content {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.box {
		display: flex;
		background: #ffffff;
		margin-bottom: 24rpx;
		height: 180rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.box_left {
		width: 30%;
		padding: 30rpx;
		box-sizing: border-box;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		background: $color;
		box-shadow: inset 0px 2px 4px 0px $bjtm;
	}

	.y_t {
		width: 30rpx;
		height: 30rpx;
		background: $bjColor;
		border-radius: 50%;
		position: absolute;
		right: -15rpx;
		top: -15rpx;
	}

	.y_b {
		width: 30rpx;
		height: 30rpx;
		background: $bjColor;
		border-radius: 50%;
		position: absolute;
		right: -15rpx;
		bottom: -15rpx;
	}

	.box_left text:nth-child(1) {
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(255, 255, 255, 0.9);
	}

	.box_left text:nth-child(2) {
		font-size: 44rpx;
		font-weight: 500;
		color: #FFFFFF;
	}

	.box_left text:nth-child(3) {
		font-size: 22rpx;
		font-weight: 400;
		color: rgba(255, 255, 255, 0.9)
	}

	.box_right {
		flex: 1;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.box_right_wz {
		width: 350rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		view {
			&:nth-child(1) {
				font-size: 30rpx;
				font-weight: 500;
				color: #222222;
			}

			&:nth-child(2) {
				font-size: 24rpx;
				font-weight: 400;
				color: #333333;
				margin: 10rpx 0;
			}

			&:nth-child(3) {
				font-size: 24rpx;
				font-weight: 400;
				color: #666666;
			}
		}
	}

	.box_right_radio {
		flex: 1;
		text-align: right;
	}
</style>